//
//  ParameterViewController.m
//  Balance
//
//  Created by Calvin Kuo on 12-04-29.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

/*
 Status: changed
 Last Merge Date: 05-30-2012
 Last Change Date: 
 Changes:
 1. check all and uncheck all
 
 */

#import "ParameterViewController.h"
#import "BUViewController.h"

@implementation ParameterViewController
@synthesize buSubtitleLabel = _buSubtitleLabel;
@synthesize ceiBUSubtitleLabel = _ceiBUSubtitleLabel;
@synthesize ceiBarBULabel = _ceiBarBULabel;
@synthesize balanceBarBULabel = _balanceBarBULabel;




#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
	return YES;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if (([segue.identifier isEqualToString:@"addBalanceBU"]) || 
        ([segue.identifier isEqualToString:@"addCEIBU"])){
        UINavigationController *navigationController =
        segue.destinationViewController;
        BUViewController *buViewController = [[navigationController viewControllers] objectAtIndex:0];
        
        buViewController.delegate = self;
        if ([segue.identifier isEqualToString:@"addBalanceBU"])
            buViewController.identifier = @"balance";
        else if ([segue.identifier isEqualToString:@"addCEIBU"])
            buViewController.identifier = @"cei";
             
    }
    
    
    if (([segue.identifier isEqualToString:@"addBalanceBarBU"]) || 
        ([segue.identifier isEqualToString:@"addCEIBarBU"])){
        UINavigationController *navigationController =
        segue.destinationViewController;
        BU2ViewController *bu2ViewController = [[navigationController viewControllers] objectAtIndex:0];
        
        bu2ViewController.delegate = self;
        if ([segue.identifier isEqualToString:@"addBalanceBarBU"])
            bu2ViewController.identifier = @"balanceBar";
        else if ([segue.identifier isEqualToString:@"addCEIBarBU"])
            bu2ViewController.identifier = @"ceiBar";
        
        
    }
}


#pragma mark BUViewControllerDelegate
- (void)buViewController:(BUViewController *)controller status:(NSString*)statusCode{
    
    if ([controller.identifier isEqualToString:@"balance"])
        _buSubtitleLabel.text = statusCode;
    else  if ([controller.identifier isEqualToString:@"cei"])
        _ceiBUSubtitleLabel.text = statusCode;
    //NSLog(@"parameter check all");
    //[self dismissViewControllerAnimated:YES completion:nil];
    
}

#pragma mark BU2ViewControllerDelegate
- (void)bu2ViewController:(BUViewController *)controller status:(NSString*)statusCode{
    
    if ([controller.identifier isEqualToString:@"balanceBar"])
        _balanceBarBULabel.text = statusCode;
    else if ([controller.identifier isEqualToString:@"ceiBar"]) 
        _ceiBarBULabel.text = statusCode;
    //NSLog(@"parameter check all");
    //[self dismissViewControllerAnimated:YES completion:nil];
    
}


- (void)viewDidUnload {
    [self setBuSubtitleLabel:nil];
    [self setCeiBUSubtitleLabel:nil];
    [self setCeiBarBULabel:nil];
    [self setBalanceBarBULabel:nil];
    [super viewDidUnload];
}
@end
